package com.sw.study.presisence.io;

import com.sw.study.common.exception.ExceptionConstants;
import com.sw.study.common.exception.sql.SqlMapConfigException;

import java.io.InputStream;

/**
 * Created by sw on 2020/3/25.
 * 获取资源文件
 *
 */
public class Resources {
    /**
     * 获取配置文件，内存存放
     * @param path
     * @return
     */
    public static InputStream getResourcesAsStream(String path)  {
        if(null==path || "".equals(path)){
            throw new SqlMapConfigException(ExceptionConstants.SQLMAPCONFIG,"SqlMapConfig.xml is not exists");
        }
        //底层代码返回null
        InputStream resourceStream=Resources.class.getClassLoader().getResourceAsStream(path);
        if(null ==resourceStream){
            throw new SqlMapConfigException(ExceptionConstants.SQLMAPCONFIG,"SqlMapConfig.xml resoling failed ");
        }
        return resourceStream;
    }

}